\documentclass[10pt,a4paper]{article} 

\usepackage{ctex} % 中文支持
\usepackage[top=2.5cm, bottom=2.5cm, left=2.5cm, right=2.5cm]{geometry} % 页边距
\usepackage{amsmath, amssymb} % 数学公式与符号
\usepackage{graphicx}
\usepackage{pythonhighlight}
\usepackage{url} 

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage{titling}
\setlength{\droptitle}{-2cm} % 标题上移

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%文档的题目、作者与日期
\author{五六七 }
\title{农业区经济聚类分析 }

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}

\maketitle

\begin{abstract}
根据一些经济指标数据，对一些农业区进行聚类分析。
\end{abstract}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%\setcounter{tocdepth}{2}
%\renewcommand\contentsname{目录}
%
%\renewcommand {\baselinestretch} {1.3}\normalsize 
%\tableofcontents 
%\renewcommand {\baselinestretch} {1.0}\normalsize


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\section{问题描述}
某地区9个农业区的7项经济指标数据如表所示。请进行聚类分析。
\begin{table}[ht!]\centering
\caption{某地区经济指标数据} \vspace{0.2cm}
\begin{tabular}{|c|c|c|c|c|c|c|c|}\hline
区代号 & 人均耕地 & 劳动耕地 & 水田比重 & 复种指数 & 粮食亩产 & 人均粮食 & 稻谷占粮食比 \\ \hline 
1&0.294&	1.093&	5.63&	113.6&	4510&	1036&	12.2  \\ \hline 
2&0.315&	0.971&	0.39&	95.1&	2773&	683&		0.85  \\ \hline 
3&0.123&	0.316&	5.28&	148.5&	6934&	611&		6.49  \\ \hline 
4&0.179&	0.527&	0.39&	111&		4458&	632&		0.92  \\ \hline 
5&0.081&	0.212&	72.04&	217.8&	12240&	791&		80.3  \\ \hline 
6&0.082&	0.211&	43.78&	179.6&	8973&	636&		48.1  \\ \hline 
7&0.075&	0.181&	65.15&	194.7&	1068&	634&		80.1  \\ \hline 
8&0.293&	0.666&	5.35&	94.9&	3679&	771&		7.8  \\ \hline 
9&0.167&	0.414&	2.9&		94.8&	4231&	574&		1.17  \\ \hline 
\end{tabular}
\end{table}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\section{建立模型}

\subsection{聚类分析的准备}

构造数据矩阵 $A=(a_{ij})_{9\times 7}$, 其中每行代表一个农业经济区，每列代表一个经济指标。
因为不同的经济指标有不同的单位，以及绝对数值差异很大，所以对数据进行归一化处理。我们使用变换公式
\begin{eqnarray}
b_{ij} = \frac{a_{ij} - \min\limits_{1\le i\le 9} a_{ij} }{\max\limits_{1\le i\le 9} a_{ij} - \min\limits_{1\le i\le 9} a_{ij}}. 
\end{eqnarray}
这个公式得到与矩阵 $A$ 相同形状的矩阵 $B$, 将每列的最小值化为0，每列的最大值化为1. 

接下来计算不同的农业区之间的两两距离，也就是矩阵 $B$ 的任意两行之间的距离。
将矩阵 $B$ 的行向量看作是欧氏空间 $\mathbb{R}^7$ 中的向量，使用欧氏空间的距离，得到计算公式为 
\begin{eqnarray}
d(\omega_i, \omega_j) = \sqrt{(b_{i1}-b_{j1})^2 + b_{i2}-b_{j2})^2 + \cdots + (b_{i7}-b_{j7})^2 }. 
\end{eqnarray}

我们使用最短距离法来聚类。两类之间的距离定义为两类之间最邻近的两个农业区之间的距离，即有公式
\begin{eqnarray}
D(G_i, G_j) = \min\limits_{\omega_s\in G_i, \omega_t\in G_j} d(\omega_s, \omega_t). 
\end{eqnarray}

\subsection{聚类分析的算法 }

\begin{enumerate}
\item  开始时每个样品自成一类，构造距离矩阵 $D_{(0)} = (d(\omega_i, \omega_j))$. 
\item  
\begin{enumerate}
\item[2.1.]  找出矩阵 $D_{(0)}$ 中除了对角线之外的所有元素的最小值，设为 $D_{pq}$, 将 $G_p$ 和 $G_q$ 合并为新类。
%\item  计算这个新类与其它类的距离。
\item[2.2.]  将矩阵 $D_{(0)}$ 的第 $p,q$ 行合并，其中的元素替换为这两行的元素的最小值。
\item[2.3.]  将矩阵 $D_{(0)}$ 的第 $p,q$ 列合并，其中的元素替换为这两列的元素的最小值。
\item[2.4.]  第 $p,q$ 行与第 $p,q$ 列相交的四个元素合并为一个元素，用零代替。
\item[2.5.]  这样得到的矩阵记为 $D_{(1)}$. 
\end{enumerate}

\item  对矩阵 $D_{(1)}$ 重复上一步，得到矩阵 $D_{(2)}$. 直到所有的样品都合并成了同一类。

\end{enumerate}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\section{编程计算}

载入数值计算包 numpy, 聚类分析包 scipy.cluster, 画图包 pylab. 
\begin{python}
import numpy as np
import scipy.cluster.hierarchy as sch
import pylab as plt
\end{python}

载入数据，把矩阵的行数保存为变量 n. 
\begin{python}
a=np.loadtxt('data11_2.txt')
n=a.shape[0]
\end{python}

将每列数据按最小最大归一化到 [0,1] 区间。
\begin{python}
b=(a-a.min(axis=0))/(a.max(axis=0)-a.min(axis=0))
\end{python}

如果想查看数据，可以在交互命令行使用下述命令，选择不用科学计数法，和只显示两位小数。
\begin{python}
np.set_printoptions(suppress=True)
np.set_printoptions(precision=2)
\end{python}

使用现成的聚类分析函数。
\begin{python}
z=sch.linkage(b)
\end{python}

画出层次聚类树的图像。
\begin{python}
s=['$\\omega_'+str(i+1)+'$' for i in range(n)]
sch.dendrogram(z, labels=s)
plt.show()
\end{python}

 \begin{figure}[ht!] \centering
 \includegraphics[height=6cm, width=10cm]{agriculture_zones_cluster.png}
\caption{层次聚类树}
 \end{figure}
 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%\section{检验模型}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\section{回答问题}

\begin{enumerate}

\item  如果将所有农业区分成2类，那么7区为单独一类，其余区为第二类。

\item  如果将所有农业区分成3类，那么7区为单独一类，5、6区为第二类，其余区为第三类。

\item  如果将所有农业区分成4类，那么1区和7区为单独两类，5、6区为第三类，其余区为第四类。

\end{enumerate}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%\section{参考文献 }
\begin{thebibliography}{99}

%\bibitem{dingtongren} 丁同仁、李承治，常微分方程教程，高等教育出版社，2022年3月第三版。
\bibitem{sishoukui-2} 司守奎,孙玺菁. \emph{Python数学建模算法与应用}, 国防工业出版社. 2022年1月第1版. 
%\bibitem{hexiaoqun-ara} 何晓群. \emph{应用回归分析(R语言版)}. 电子工业出版社. 2017年7月第1版. 
%\bibitem{dalgaard} Peter Dalgaard 著, 郝智恒等译. \emph{R语言统计入门}. 人民邮电出版社. 2014年6月第1版. 
\bibitem{gaohuixuan} 高惠璇. \emph{应用多元统计分析}, 北京大学出版社. 2005年1月第1版. 
\bibitem{hexiaoqun-multi} 何晓群. \emph{多元统计分析}, 中国人民大学出版社. 2019年6月第5版. 


\end{thebibliography}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\end{document}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%





